/**
 *
 * jQuery is required
 * jamal is required
 * 
 * JamalBuilder:  
 * Copyright (c)  2007, Georg Leciejewski <http://blog.mediaprojekte.de/>
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @filesource
 * @copyright        Copyright (c) 2007, Georg Leciejewski
 * @link            
 * @package          jamalBuilder
 * @subpackage       jamalBuilder.models
 * @since            jamalBuilder v 0.22
 * @version          $Revision:  $
 * @modifiedby       $LastChangedBy:  $
 * @lastmodified     $Date: $
 * @license          http://www.opensource.org/licenses/mit-license.php The MIT License
 */
 
/**
 * Setting Model
 *
 * This is a setting model
 * Handling the data for the settings:
 *  - save xml file
 *  - deliver its contents
 */
$j.m({ Setting: {
	
	/**
	 * save new settings into an xml file
	 */
	saveXml: function (data) {
		
		//open config filestream
		var settings_file = new air.File();
		//convert data to xml
		var xml = $j.current.dataToXml(data);
		
		//jamal.log(data[0].value);
		//WRITE
		var stream = new air.FileStream();
		
		stream.open( settings_file, air.FileMode.WRITE );
			
		//save data
		stream.writeUTF(xml, air.File.systemCharset );
		//close stream
		stream.close();	
		
		
		//close stream
	},
	
	dataToXml:function (data) {
		
		jamal.log('Start SettingModel convertToXml');
		var xml_string = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n';
		for(var i = 0; i < data.length; i++)
		{
			xml_string +='<setting>\n';
			xml_string +='<name>'+data.name+'</name>\n';
			xml_string +='<value>'+data.value+'</value>\n';
			xml_string +='</setting>';
			
		}
		//xml_string +='';
		return xml_string;
	}
}
});
